﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Admin.Controls
{
    public partial class ListEmployee : System.Web.UI.UserControl
    {
        public int count;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    //Them du lieu vao cat 1
                    count = 1;
                    rpt_employee.DataSource = DAL.DCollector.DBCollector.Instance.SelectSQL("Select * from tbl_Employee");
                    rpt_employee.DataBind();
                }
            }
            catch (Exception)
            {
                Response.Redirect("/error.htm");
            }
        }

        protected void rpt_employee_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                // Xoa
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                DataTable dt = DAL.DCollector.DBCollector.Instance.SelectSQL("Select Employee_Email from tbl_Employee Where Employee_ID = " + id);
                string email = dt.Rows[0]["Employee_Email"].ToString();
                LIB.Validate.SendMail(email, "Chào bạn! Tài khoản A-mark của bạn đã bị xóa do vi phạm điều khoản công ty !");
                DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_Employee", "Employee_ID", id.ToString());              
                Response.Redirect("/Admin/Index.aspx?panel=4&sub=3");
            }
        }
    }
}